﻿using System.Collections.Generic;
using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.RepositoriesContracts.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;

namespace MaxStoreShop.Logic.Services.Directories
{
    public class MeasureTypeService : IMeasureTypeService
    {
        readonly IMeasureTypeRepository _repository;
        public MeasureTypeService(IMeasureTypeRepository repository)
        {
            _repository = repository;
        }

        public IEnumerable<MeasureType> GetAllMeasures()
        {
            return _repository.GetAllMeasures();
        }

        public void DeleteMeasure(MeasureType measureType)
        {
            if (measureType == null)
                throw new ErpRuntimeException("Не указан вид измерения для удаления!");

            _repository.DeleteMeasure(measureType.Id);
        }

        public void SaveMeasure(MeasureType measureType)
        {
            if (measureType == null)
                throw new ErpRuntimeException("Не указан вид измерения для сохранения!");

            if (string.IsNullOrWhiteSpace(measureType.Name))
                throw new ErpRuntimeException("Не задано имя для сохраняемого вида измерения!");

            if (string.IsNullOrWhiteSpace(measureType.ShortName))
                throw new ErpRuntimeException("Не задано короткое наименование сохраняемого вида измерения!");

            _repository.SaveMeasure(measureType);
        }
    }
}
